﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OneSoft.EntityCore;
using OneSoft.DataAccess;
using System.Data;

using BySoft.Server.Common.Entity;
using BySoft.Server.Common.Schema;
using BySoft.Server.Consts;

namespace BySoft.Server.DataAccess
{
    public partial class SysExceptonLogDA
    {
        public static DataTable GetExceptionLogList(string moduleID,string startDate,string endDate, string exceptionType, int pageIndex,
                                                   int pageSize, out int count)
        {
            #region SQL Server
            DataAccessParameterCollection parameters = new DataAccessParameterCollection();

            string sSql = "SELECT ExceptionLogID, ModuleID, ModuleName, RecordTime, ExceptionMessage, OrgStackTrace, ExceptionUrl, IPAddress, UserID, UserName, ActionType, ExceptionType FROM SYS_ExceptonLog WHERE 1=1 ";

            if (!String.IsNullOrEmpty(moduleID))
            {
                sSql += " AND " + SysExceptonlogTable.C_MODULEID + "=@moduleID";
                parameters.AddWithValue("@moduleID", moduleID);
            }
            if (!String.IsNullOrEmpty(exceptionType))
            {
                sSql += " AND " + SysExceptonlogTable.C_EXCEPTIONTYPE + "=@expType";
                parameters.AddWithValue("@expType", exceptionType);
            }
            if (!String.IsNullOrEmpty(startDate))
            {
                sSql += " AND " + SysExceptonlogTable.C_RECORDTIME + " >=@StartDate";
                parameters.AddWithValue("@StartDate", Convert.ToDateTime(startDate));
            }
            if (!String.IsNullOrEmpty(endDate))
            {
                sSql += " AND " + SysExceptonlogTable.C_RECORDTIME + " <=@EndDate";
                parameters.AddWithValue("@EndDate", Convert.ToDateTime(endDate + " 23:59:59"));
            }
            sSql += " ORDER BY " + SysExceptonlogTable.C_RECORDTIME + " DESC ";
            //return DataAccessCommon.ExecuteDataTablePagingFor2000(sSql, pageIndex, pageSize, parameters, out count, SysExceptonlogTable.C_RECORDTIME + " DESC ");
            return DataAccessCommon.ExecuteDataTablePaging(sSql, pageIndex, pageSize, parameters, out count);
            #endregion
        }

        public static DataTable GetExceptionTypeList()
        {
            DataAccessParameterCollection parameters = new DataAccessParameterCollection();
            string strSql = "SELECT DISTINCT ExceptionType FROM SYS_ExceptonLog";
            return DataAccessCommon.Select(strSql, parameters).Tables[0];
        }
    }
}
